import React from 'react'
import Component, { mapStateToProps, mapDispatchToProps } from '@components/Component'
import { connect } from 'react-redux'
import { Table, message } from 'antd'
import style from './Index.module.less'

function getColumns () {
  return [
    {
      title: '案件相关人',
      dataIndex: 'ref'
    },
    {
      title: '仲裁地位',
      dataIndex: 'action_subject'
    },
    {
      title: '仲裁员',
      dataIndex: 'arbitrator'
    },
    {
      title: '回避情形',
      dataIndex: 'ref_info'
    }
  ]
}

class Avoid extends Component {
  state = {
    loading: false,
    list: []
  }

  getList () {
    this.setState({ loading: true })
    this.$get('/api/xapc/case/arbitratorwithdraw', {
      caseid: this.props.caseDetail.id
    }).then(res => {
      this.setState({ loading: false })
      if (res.status === 1) {
        this.setState({
          list: res.data.map(li => {
            li.key = li.arbitratorid
            return li
          })
        })
      } else {
        message.warning(res.message)
      }
    }).catch(() => this.setState({ loading: false }))
  }

  componentDidMount () {
    this.getList()
  }

  render () {
    return (
      <Table className={style.mt16} loading={this.state.loading} size='small' columns={getColumns.call(this)} dataSource={this.state.list} />
    )
  }
}

const mapState = mapStateToProps(function (state) {
  return {
    userInfo: state.basic.userInfo
  }
})

const mapDispatch = mapDispatchToProps(function (dispatch) {
  return {
  }
})

export default connect(mapState, mapDispatch)(Avoid)
